//package com.plian.system.service.yth.impl;
//
//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.plian.Tools.CollectionUtil;
//import com.plian.Tools.StringUtil;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.constant.tb.TripleStatusConstant;
//import com.plian.system.entity.tb.*;
//import com.plian.system.entity.yth.meet.*;
//import com.plian.system.mapper.yth.meet.*;
//import com.plian.system.service.yth.IConferenceMeetingService;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Optional;
//import java.util.stream.Collectors;
//
///**
// * @Description: TODO
// * @Author: Take-off
// * @Date: 2023/4/18 5:03 PM
// * @Param
// * @return
// * @Version: 1.0
// **/
//@Slf4j
//@Service
//@AllArgsConstructor
//public class ConferenceMeetingServiceImpl extends ServiceImpl<ConferenceMeetingMapper, ConferenceMeeting> implements IConferenceMeetingService {
//
//    private final ConferenceMeetingUserMapper meetingUserMapper;
//
//    private final ConferenceTopicMapper topicMapper;
//
//    private final ConferenceTopicRegulationMapper topicRegulationMapper;
//
//    private final ConferenceTopicEventMapper topicEventMapper;
//
//    private final ConferenceTopicUserMapper topicUserMapper;
//
//    private final String YTH_DATASOURCE_TYPE = "3";
//
//    @Override
//    @DS("slave_1")
//    public List<TripleMeeting> getAllProject(Date startTime, Date endTime){
//        List<TripleMeeting> tripleMeetings = new ArrayList<>();
//        List<ConferenceMeeting> conferenceMeetings = list(new LambdaQueryWrapper<ConferenceMeeting>()
//                .gt(Optional.ofNullable(startTime).isPresent(), ConferenceMeeting::getCreateTime, startTime)
//                .le(Optional.ofNullable(endTime).isPresent(), ConferenceMeeting::getCreateTime, endTime)
//        );
//        if (CollectionUtil.isNotEmpty(conferenceMeetings)){
//            tripleMeetings = conversion(conferenceMeetings);
//        }
//        return tripleMeetings;
//    }
//
//    /**
//     * @Description: //TODO 转换会议对象
//     * @Author: Take-off
//     * @Date: 7:44 PM 2023/4/18
//     * @Param: [conferenceMeetings]
//     * @return: java.util.List<com.plian.system.entity.tb.TripleMeeting>
//     **/
//    private List<TripleMeeting> conversion(List<ConferenceMeeting> conferenceMeetings) {
//        List<TripleMeeting> tripleMeetings = new ArrayList<>();
//
//        List<Long> meetIds = conferenceMeetings.stream().map(ConferenceMeeting::getId).collect(Collectors.toList());
//        //参会人员
//        List<ConferenceMeetingUser> meetingUsers = meetingUserMapper.selectList(Wrappers.<ConferenceMeetingUser>lambdaQuery().in(ConferenceMeetingUser::getMeetingId, meetIds));
//        //议题
//        List<ConferenceTopic> topics = topicMapper.selectList(Wrappers.<ConferenceTopic>lambdaQuery().in(ConferenceTopic::getMeetingId, meetIds));
//        //议题制度关联表
//        List<ConferenceTopicRegulation> topicRegulations = new ArrayList<>();
//        //议题事项关联表
//        List<ConferenceTopicEvent> topicEvents = new ArrayList<>();
//        //议题人员关联表 - 列席
//        List<ConferenceTopicUser> topicUsers = new ArrayList<>();
//        if (CollectionUtil.isNotEmpty(topics)){
//            List<Long> topicIds = topics.stream().map(ConferenceTopic::getId).collect(Collectors.toList());
//            topicRegulations = topicRegulationMapper.selectList(Wrappers.<ConferenceTopicRegulation>lambdaQuery().in(ConferenceTopicRegulation::getTopicId, topicIds));
//            topicEvents = topicEventMapper.selectList(Wrappers.<ConferenceTopicEvent>lambdaQuery().in(ConferenceTopicEvent::getTopicId, topicIds));
//            topicUsers = topicUserMapper.selectList(Wrappers.<ConferenceTopicUser>lambdaQuery().in(ConferenceTopicUser::getTopicId, topicIds));
//        }
//
//        for (ConferenceMeeting meeting:conferenceMeetings) {
//            TripleMeeting tripleMeeting = new TripleMeeting();
//            Optional.ofNullable(meeting.getReportOrgId()).ifPresent(m -> {
//                tripleMeeting.setFillingUnitId(m.toString());
//            });
//            Optional.ofNullable(meeting.getReportUserId()).ifPresent(m -> {
//                tripleMeeting.setReportUser(m.toString());
//            });
//            tripleMeeting.setReportTime(meeting.getReportTime());
//            tripleMeeting.setMeetingNumber(meeting.getNumber());
//            tripleMeeting.setMeetingName(meeting.getName());
//            switch (meeting.getType()) {
//                case 1:
//                    tripleMeeting.setMeetingType("144001");
//                    break;
//                case 2:
//                    tripleMeeting.setMeetingType("144004");
//                    break;
//                case 3:
//                    tripleMeeting.setMeetingType("144003");
//                    break;
//                case 4:
//                    tripleMeeting.setMeetingType("144002");
//                    break;
//                default:
//                    break;
//            }
//            tripleMeeting.setMeetingTime(meeting.getBeginTime());
//            tripleMeeting.setMeetingPlace(meeting.getAddress());
//            tripleMeeting.setMeetingHost(meeting.getCompereName());
//            tripleMeeting.setSummaryAttachId(meeting.getSummaryAttachId());
//            tripleMeeting.setDataSource(YTH_DATASOURCE_TYPE);
//            tripleMeeting.setDataSourceId(meeting.getId().toString());
//            //议题
//            if (CollectionUtil.isNotEmpty(topics)) {
//                List<ConferenceTopic> topicList = topics.stream().filter(m -> meeting.getId().equals(m.getMeetingId())).collect(Collectors.toList());
//                if (CollectionUtil.isNotEmpty(topicList)) {
//                    List<TripleMeetingTopic> tripleMeetingTopics = new ArrayList<>();
//                    for (ConferenceTopic topic : topicList) {
//                        TripleMeetingTopic tripleMeetingTopic = new TripleMeetingTopic();
//                        tripleMeetingTopic.setTopicName(topic.getName());
//                        tripleMeetingTopic.setTopicNumber(topic.getNumber());
//                        tripleMeetingTopic.setFormType(String.valueOf(FormTypeConstant.PF_TRIPLE_MEETING_TOPIC));
//                        if (topic.getTopicType() != null) {
//                            switch (topic.getTopicType()) {
//                                case 1:
//                                    tripleMeetingTopic.setTopicType("145001");
//                                    break;
//                                case 2:
//                                    tripleMeetingTopic.setTopicType("145002");
//                                    break;
//                                case 3:
//                                    tripleMeetingTopic.setTopicType("145003");
//                                    break;
//                                case 4:
//                                    tripleMeetingTopic.setTopicType("145004");
//                                    break;
//                                default:
//                                    break;
//                            }
//                        }
//                        List<TopicRelevance> topicRelevances = new ArrayList<>();
//                        //议题制度关联
//                        if (CollectionUtil.isNotEmpty(topicRegulations)) {
//                            List<ConferenceTopicRegulation> regulations = topicRegulations.stream().filter(m -> topic.getId().equals(m.getTopicId())).collect(Collectors.toList());
//                            if (CollectionUtil.isNotEmpty(regulations)) {
//                                for (ConferenceTopicRegulation regulation : regulations) {
//                                    TopicRelevance relevance = new TopicRelevance();
//                                    relevance.setRelevanceId(regulation.getRegulationId());
//                                    relevance.setRelevanceType(2);
//                                    Optional.ofNullable(regulation.getIsPass()).ifPresent(m -> {
//                                        relevance.setResult(m == 0 ? 4 : 3);
//                                    });
//                                    relevance.setRemarks(regulation.getRejectReason());
//                                    topicRelevances.add(relevance);
//                                }
//                            }
//                        }
//                        //议题事项关联
//                        if (CollectionUtil.isNotEmpty(topicEvents)) {
//                            List<ConferenceTopicEvent> events = topicEvents.stream().filter(m -> topic.getId().equals(m.getTopicId())).collect(Collectors.toList());
//                            if (CollectionUtil.isNotEmpty(events)) {
//                                for (ConferenceTopicEvent event : events) {
//                                    TopicRelevance relevance = new TopicRelevance();
//                                    relevance.setRelevanceId(event.getEventId());
//                                    relevance.setRelevanceType(1);
//                                    Optional.ofNullable(event.getIsPass()).ifPresent(m -> {
//                                        relevance.setResult(m == 0 ? 4 : 3);
//                                    });
//                                    relevance.setRemarks(event.getRejectReason());
//                                    topicRelevances.add(relevance);
//                                }
//                            }
//                        }
//                        tripleMeetingTopic.setTopicRelevances(topicRelevances);
//                        tripleMeetingTopics.add(tripleMeetingTopic);
//                    }
//                    tripleMeeting.setMeetingTopics(tripleMeetingTopics);
//                    //列席人员
//                    if (CollectionUtil.isNotEmpty(topicUsers)) {
//                        List<MeetingAttendee> meetingAttendees = new ArrayList<>();
//                        List<ConferenceTopicUser> topicUserList = topicUsers.stream().filter(m -> topicList.stream().map(ConferenceTopic::getId).collect(Collectors.toList())
//                                .contains(m.getTopicId())).collect(Collectors.toList());
//                        for (ConferenceTopicUser topicUser : topicUserList) {
//                            MeetingAttendee meetingAttendee = new MeetingAttendee();
//                            if (Optional.ofNullable(topicUser.getUserId()).isPresent()) {
//                                meetingAttendee.setName(topicUser.getUserId().toString());
//                            } else {
//                                meetingAttendee.setName(topicUser.getExternalUserName());
//                            }
//                            meetingAttendee.setAttendeeStatus(1);
//                            meetingAttendees.add(meetingAttendee);
//                        }
//                        tripleMeeting.setMeetingAttendees(meetingAttendees);
//                    }
//                }
//            }
//            //参会人员
//            if (CollectionUtil.isNotEmpty(meetingUsers)) {
//                List<MeetingParticipant> meetingParticipants = new ArrayList<>();
//                List<ConferenceMeetingUser> meetingUserList = meetingUsers.stream().filter(m -> meeting.getId().equals(m.getMeetingId())).collect(Collectors.toList());
//                for (ConferenceMeetingUser meetingUser : meetingUserList) {
//                    MeetingParticipant meetingParticipant = new MeetingParticipant();
//                    if (Optional.ofNullable(meetingUser.getUserId()).isPresent()) {
//                        meetingParticipant.setName(meetingUser.getUserId().toString());
//                    } else {
//                        meetingParticipant.setName(meetingUser.getExternalUserName());
//                    }
//                    if (meetingUser.getIsPresent() != null) {
//                        meetingParticipant.setAttendeeStatus(meetingUser.getIsPresent() == 0 ? 2 : 1);
//                    }
//                    meetingParticipant.setRemarks(meetingUser.getAbsentReason());
//                    meetingParticipants.add(meetingParticipant);
//                }
//                tripleMeeting.setMeetingParticipants(meetingParticipants);
//            }
//            tripleMeeting.setMeetStatus(TripleStatusConstant.FINISHRECORD);
//            tripleMeetings.add(tripleMeeting);
//        }
//        List<TripleMeeting> collect = tripleMeetings.stream().filter(m -> StringUtil.isNotBlank(m.getMeetingHost())).collect(Collectors.toList());
//        return tripleMeetings;
//    }
//
//}
